<template>
  <div class="mod-section__section">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectCode" placeholder="项目编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.sectionName" placeholder="标包名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.sectionCode" placeholder="标包编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <ren-select v-model="state.dataForm.dealStatus" dict-type="deal_status" placeholder="标段状态" clearable></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('section:section:save') && state.dataForm.purchaseProjectId" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('section:section:delete')" type="danger" @click="state.deleteHandle()">删除</el-button>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:export')" type="info" @click="state.exportHandle()">导出</el-button>-->
<!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
              <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <el-table-column prop="purchaseProjectName" label="项目名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="purchaseProjectCode" label="项目编号" header-align="center" align="center"></el-table-column>
              <el-table-column prop="sectionName" label="标包名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="sectionCode" label="标包编号" header-align="center" align="center"></el-table-column>
<!--              <el-table-column prop="purchaseProjectId" label="关联的采购项目" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="sectionContent" label="标包内容" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="sectionCategory" label="标包类别" header-align="center" align="center"></el-table-column>-->
              <el-table-column prop="estimatesMoney" label="概算金额(元)" header-align="center" align="center" width = "110"></el-table-column>
<!--              <el-table-column prop="isAptitude" label="是否要求上传资质" header-align="center" align="center"></el-table-column>-->
              <el-table-column prop="dealStatus" label="标段状态" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("deal_status", scope.row.dealStatus) }}
                </template>
              </el-table-column>
              <el-table-column prop="dealMoney" label="成交金额(元)" header-align="center" align="center" width = "110"></el-table-column>
<!--              <el-table-column prop="dealBodyShareId" label="成交企业共享平台" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="dealBodyName" label="成交企业名称" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="dealTime" label="成交时间" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createUser" label="项目创建人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createTime" label="项目创建时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateUser" label="最后更新人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateTime" label="最后更新时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="180">
        <template v-slot="scope">
          <el-button type="primary" link @click="detailHandle(scope.row.sectionId)">详情</el-button>
          <el-button v-if="state.hasPermission('section:section:update')" type="primary" link @click="addOrUpdateHandle(scope.row.sectionId)">修改</el-button>
          <el-button v-if="state.hasPermission('section:section:delete')" type="primary" link @click="state.deleteHandle(scope.row.sectionId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <detail ref="detailRef" @refreshDataList="state.getDataList">确定</detail>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./section-add-or-update.vue";
import detail from "./section-detail.vue";

const props = defineProps({
  purchaseProjectId: {
    type: String,
    required: true
  },
   purchaseProjectCode: {
    type: String,
    required: true
  }
});

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/section/section/page",
  getDataListIsPage: true,
  exportURL: "/section/section/export",
  deleteURL: "/section/section",
  dataForm: {
    purchaseProjectId: props.purchaseProjectId,
    purchaseProjectCode: props.purchaseProjectCode,
    dealStatus : ''
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.dataForm.purchaseProjectId = props.purchaseProjectId;
  addOrUpdateRef.value.dataForm.purchaseProjectCode = props.purchaseProjectCode;
  console.log("111111111111aaaa"+ props.purchaseProjectId);
  console.log("111111111111yyyyyy"+ props.purchaseProjectCode);
  addOrUpdateRef.value.init(id);
};

const detailRef = ref();
const detailHandle = (id?: number) => {
  detailRef.value.init(id);
};

</script>
